package com.leo.quartz.service.impl;

import com.leo.base.AbstractService;
import com.leo.base.PageResponse;
import com.leo.base.ReturnResponse;
import com.leo.quartz.common.lang.ReturnCodeConstant;
import com.leo.quartz.common.request.MyJobDetailRequestParam;
import com.leo.quartz.common.response.task.TriggerVO;
import com.leo.quartz.entity.TriggerPO;
import com.leo.quartz.repository.TriggerRepository;
import com.leo.quartz.service.JobTriggerService;
import com.leo.util.PoUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author liusl
 * @version 1.0
 * @date 2018/12/9 16:10
 */
@Service
public class JobTriggerServiceImpl extends AbstractService implements JobTriggerService {

    private TriggerRepository triggerRepository;

    public JobTriggerServiceImpl(TriggerRepository triggerRepository) {
        this.triggerRepository = triggerRepository;
    }

    @Override
    public ReturnResponse getJobDtailById(Long id) {
        return null;
    }

    @Override
    public PageResponse<TriggerVO> queryTriggerList(MyJobDetailRequestParam requestParam) {
        Specification<TriggerPO> specification = buildSpecification(requestParam, TriggerPO.class);
        Page<TriggerPO>  pages = triggerRepository.findAll(specification, requestParam.buildPageRequest());
        List<TriggerVO> triggerVOS =  PoUtils.copyBeans(pages.getContent(),TriggerVO.class);
        return new PageResponse<>(ReturnCodeConstant.SUCCESS, "", pages.getTotalElements(),triggerVOS);
    }

    @Override
    public ReturnResponse removeJob(Long id) {
        return null;
    }

    @Override
    public ReturnResponse addJob(MyJobDetailRequestParam param) {
        return null;
    }

    @Override
    public ReturnResponse editJobDetail(MyJobDetailRequestParam param) {
        return null;
    }

}
